import java.util.Map;
import java.util.Stack;
import java.util.HashMap;
public class ShuntYardAlgo {
	Stack<Character> stack = new Stack<Character>();
	static Map <Character,Integer> map; 
	public int count;
	private static double value;
	private String input;
	private final static int Size = 10000;
	static Node[] node;
	public ShuntYardAlgo(String input){
		this.input = input;
//		int maxSize = input.length();
//		stack = new Stack();
		node = new Node[Size];
		map = new HashMap<Character,Integer>();
	}
	public Node[] Shunt(){
		
		Stack<Character> oper = new Stack<Character>();
		for(int i=0;i<input.length();i++){
			boolean inNum = true;
			Character char2 = null;
			Character char1 = input.charAt(i);
			if(Character.isDigit(char1)){
				value = Double.parseDouble(char1.toString());
				i++;
				if(!(i==input.length())){
					char2=input.charAt(i);
					if(Character.isDigit(char2)){
						value = 10*value + Double.parseDouble(char2.toString());
						inNum = false;
					}
				}
				if(inNum){
					i--;
					inNum = true;
				}
				node[count++] = new Node(value,'a');
			}
			else{
				switch(char1){
				case'(':
					oper.push(char1);
					break;
				case')':
				{
					while(!stack.isEmpty()){
						char onTop = (char) stack.pop();
						if(onTop=='('){
							break;
						}else{
							node[count++] = new Node(-1,onTop);
						}
					}
				}
				
					break;
				case'+':
				case'-':
				case'*':
				case'/':
				{
					while(!stack.isEmpty()){
						char onTop = (char) stack.pop();
						if(onTop=='('){
							stack.push(onTop);
							break;
						}else{
							if(map.get(char1)>2){
								stack.push(onTop);
								break;
							}else{
								node[count++]  = new Node(-1,onTop);
							}
						}
					}
					stack.push(char1);
					break;
				}
				}
			}
		}
		while(!stack.empty()){
			Character onTop = (Character) stack.pop();
			node[count++] = new Node(-1,onTop);
		}
		return node;
}
	
	public void Init(){
		map.put('+', 1);
		map.put('-', 1);
		map.put('*', 2);
		map.put('/', 2);
		map.put('(', 0);
	}
//	public void getOper(char ch){
//		while(!stack.isEmpty()){
//			Character onTop = (Character) stack.pop();
//			if(onTop=='('){
//				stack.push(onTop);
//				break;
//			}else{
//				if(map.get(ch)>map.get(onTop)){
//					stack.push(onTop);
//					break;
//				}else{
//					node[count++]  = new Node(-1,onTop);
//				}
//			}
//		}
//		stack.push(ch);
//	}
//	public void getParen(){
//		while(!stack.isEmpty()){
//			char onTop = (char) stack.pop();
//			if(onTop=='('){
//				break;
//			}else{
//				node[count++] = new Node(-1,onTop);
//			}
//		}
//	}
//	
}
